/**
 * @Copyright 
 * @Project inetdisk
 * @CreateTime 2015-10-29 上午8:45:49
 */
package ren.wxyz.inetdisk.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import ren.wxyz.inetdisk.dao.UserDao;
import ren.wxyz.inetdisk.model.UserInfo;

/**
 * <p>
 * 用户访问的内存实现
 * </p>
 * @Author wxyz
 * @CreateTime 2015-10-29 上午8:45:49 init class
 */
@Repository
public class UserDaoMemImpl implements UserDao {

	/**
	 * 用户列表
	 */
	static final List<UserInfo> users = new ArrayList<>();
	
	static {
		UserInfo user = new UserInfo();
		user.setId(1L);
		user.setAccount("admin");
		user.setPasswd("KKwI0xsLK2sjpCrfu0iL4R.afqinbpe39TxGwbcFIZA==");
		user.setPasswdSalt("osgpaUQF");
		user.setNickName("管理员");
		user.setLockFlag("0");
		user.setDelFlag("0");
		users.add(user);
		
		user = new UserInfo();
		user.setId(2L);
		user.setAccount("test1");
		user.setPasswd("lh3QzOvG42oLwtjy81ieh6GaiPPSZbdRIDMn4H9avr5==");
		user.setPasswdSalt("QFBe0gou");
		user.setNickName("测试1");
		user.setLockFlag("0");
		user.setDelFlag("0");
		users.add(user);
		
		user = new UserInfo();
		user.setId(3L);
		user.setAccount("test2");
		user.setPasswd("eMBilRsLXeER7s8BElM4RN8/aXZFD68ABgkCbl2.Ia0==");
		user.setPasswdSalt("AQQVI9qp");
		user.setNickName("测试2");
		user.setLockFlag("1");
		user.setDelFlag("0");
		users.add(user);
		
		user = new UserInfo();
		user.setId(4L);
		user.setAccount("test3");
		user.setPasswd("oZNQJZuWQhr/mlDqLC6OGNhLkvA27OxL3/s6NG03Hn7==");
		user.setPasswdSalt("wv5ge1/v");
		user.setNickName("测试3");
		user.setLockFlag("1");
		user.setDelFlag("1");
		users.add(user);
	}

	@Override
	public UserInfo findByAccount(String account) {
		for (UserInfo user : users) {
			if (user.getDelFlag().equals("0") && user.getAccount().equals(account)) {
				return user;
			}
		}
		
		return null;
	}

}
